import React, { useState, useEffect } from 'react';
import tab from '@/hoc/tab';
import { Input, Button, Table } from 'antd';
import { defaultAxios } from '@/request/request';

let params1 = ' /getChatLog';
function chat(props: any) {
  const { Search } = Input;
  const { arr, fatherecho, total } = props;
  const [data, setData] = useState([]);
  useEffect(() => {
    setData(arr);
  }, [arr]);
  const columns: any = [
    {
      title: 'ID',
      dataIndex: 'log_id',
    },
    {
      title: '发送人',
      dataIndex: 'from_name',
    },
    {
      title: '消息',
      dataIndex: 'message',
    },
    {
      title: '接收人',
      dataIndex: 'to_name',
    },
    {
      title: '创建时间',
      dataIndex: 'create_time',
    },
  ];
  const onSearch = (value: any) => {
    console.log(value);
    defaultAxios.get('/getChatLog', { params: { value } }).then((res: any) => {
      console.log(res.data.arr);
      setData(res.data.arr);
    });
  };
  return (
    <div
      style={{
        border: '1px solid #ccc',
        width: '1600px',
        height: '80px',
      }}
    >
      <div style={{ marginTop: '30px' }}>
        <Button type="dashed">发送人</Button>
        <Search
          placeholder="请输入搜索内容"
          onSearch={onSearch}
          enterButton="搜索"
          style={{ width: 190 }}
        />
        <Table
          columns={columns}
          dataSource={data}
          pagination={{ pageSize: 5, showQuickJumper: true, total }}
        />
      </div>
    </div>
  );
}

export default tab(chat, params1);
